<?php
class threads_controller {
  function __construct() {
    $this->thread = new thread($GLOBALS['ident']);
  }
  function index() {
    $this->all();
    load_view('threads/list.php');
  }
  // display
  function all() {
    $GLOBALS['threads'] = $this->thread->find_all();
  }
  function show() {
    $GLOBALS['thread'] = $this->thread;
  }
  function feed() {
    $post = new post();
    $GLOBALS['feed'] = split_by_day($post->find_all('order by time desc'),'time');
  }
  // action
  function save() {
    $this->thread->name = $_POST['thread_name'];
    $this->thread->description = $_POST['thread_desc'];
    $this->thread->save();
    redirect('threads/list');
  }
  function savepost() {
    $post = new post();
    $post->thread_id = $GLOBALS['ident']; // threads/savepostt/[thread id]
    $post->name = $_POST['post_name'];
    $post->time = time();
    $post->body = $_POST['post_body'];
    $post->save();
    redirect('threads/show/'.$GLOBALS['ident']."#post-".$post->id);
  }
  function delete() {
    $this->thread->delete_all();
    redirect('threads/list');
  }
}
?>